﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Security.Cryptography.X509Certificates;
using System.Text;
using System.Threading.Tasks;

namespace ECS
{
    public class System
    {
        public static int CreateEntity(ref Entities world)
        {
            for (int i = 0; i < 100; i++)
            {
                if (world.Mask[i] == (int) Component.Mask.None)
                {
                    return i;
                }
            }

            Console.WriteLine("空间不够了！");
            return 100;
        }

        public static void DestoryEntity(ref Entities world, int index)
        {
            world.Mask[index] = (int) Component.Mask.None;
        }

        public static void CreatePlantable(ref Entities world, string name, float x, float y)
        {
            int PlantableMask = (int) Component.Mask.Name | (int) Component.Mask.Position;

            int index = CreateEntity(ref world);
            if (index == 100)
            {
                return;
            }

            world.Mask[index] = PlantableMask;

            world.names[index].value = name;

            world.positions[index].x = x;
            world.positions[index].y = y;
        }

        public static void CreateScaleable(ref Entities world, string name, float x, float y)
        {
            int ScaleableMask = (int) Component.Mask.Name | (int) Component.Mask.Scale;

            int index = CreateEntity(ref world);
            if (index == 100)
            {
                return;
            }

            world.Mask[index] = ScaleableMask;

            world.names[index].value = name;
            world.scales[index].x = x;
            world.scales[index].y = y;
        }

        public static void FindAllPlantable(Entities world)
        {
            int PlantableMask = (int)Component.Mask.Name | (int)Component.Mask.Position;

            for (int i = 0; i < 100; i++)
            {
                if ((world.Mask[i] & PlantableMask) == PlantableMask)
                {
                    Console.Write(i + " ");
                    world.names[i].
                }
            }

            Console.WriteLine();
        }

        public static void GetAllPosition(Entities world)
        {
            int PositionMask = (int) Component.Mask.Position;
            for (int i = 0; i < 100; i++)
            {
                if ((world.Mask[i] & PositionMask) == PositionMask)
                {
                    Console.Write(i + ":" + "(" + world.positions[i].x + "," + world.positions[i].y + ")" + " ");
                }
            }

            Console.WriteLine();
        }

        public static void GetAllScale(Entities world)
        {
            int ScaleMask = (int)Component.Mask.Scale;
            for (int i = 0; i < 100; i++)
            {
                if ((world.Mask[i] & ScaleMask) == ScaleMask)
                {
                    Console.Write(i + ":" + "(" + world.scales[i].x + "," + world.scales[i].y + ")" + " ");
                }
            }

            Console.WriteLine();
        }
    }
}
